// 03admin/12bizAuth/whcatAuth/whcatAuth.js

var co = require('../../../../resource/js/common.js')
var app = getApp()
var _this, _data,_opt
var _qrParam

Page({
   data: {
      inviteQRCode: '', //二维码图片
      busLicenseName: '', // 商家营业执照名称
      legalPersonName: '' //法人名称
   },

   onLoad: function(opt) {
      console.log('opt==', opt)
      _this = this
      _data = this.data
      _opt = opt
      this.createQRCode()
      this.getAuthInfo()
   },

   onUnload: function() {
      _qrParam = ''
   },

   //获取商家营业执照信息
   getAuthInfo: function() {
      co.getShareApi('biz/Bizmg/getAuthInfo', {
         Biz_ID: _opt.Biz_ID
      }, function(res) {
         if (res.code == 0) {
            var obj = res.data
            _this.setData({
               busLicenseName: obj.Name,
               legalPersonName: obj.LegalPersonName
            })
         }
      })
   },

   //创建二维码
   createQRCode: function() {
      var param = app.Data.app
      console.log(param)
      param.scene = "BizID." + _opt.Biz_ID + '.User_ID.' + app.Data.userInfo.User_ID
      //param.wxapp_page_path = '03admin/09getMoney/03bankCard/01addBankCard/addBankCard'
      param.wxapp_page_path = '01login/regUser/userReg'
      var url = "https://h5.52g3.cc/" + param.appid + '/' + param.wxapp_page_path + "/" + param.scene + 's.png'
      console.log('url==' + url)
      _this.setData({
         inviteQRCode: url
      })
      _qrParam = param
   },

   //判断图片是否存在
   // getImageInfo: function(img, callback) {
   //    wx.getImageInfo({
   //       src: img,
   //       success: function(res) {
   //          console.log('【wx.getImageInfo success:res】', res)
   //          //callback(1)
   //          callback(res)
   //       },
   //       fail: function(res) {
   //          console.log('【wx.getImageInfo fail:res】', res)
   //          //callback(0)
   //          callback(res)
   //       },
   //    })
   // },

   //图片加载错误时回调(第一次)
   onImgError: function(e) {
      co.getShareApi('api/Weixin/getWxAppCodeUnlimit', _qrParam, function(res) {
         if (res.code == 0) {
            _this.setData({
               inviteQRCode: res.data.wxapp_code_url
            })
         }
      })
   },

   //分享
   onShareAppMessage: function() {
      var urlParam = ''
      if (app.Data.userInfo.User_ID) {
         urlParam = '?scene=BizID.' + _opt.Biz_ID + '.User_ID.' + app.Data.userInfo.User_ID
      }
      console.log('【app.Data.userInfo】==', app.Data.userInfo)
      console.log('【urlParam】==', urlParam)
      return {
         title: '法人扫一扫认证微信',
         //path: '/03admin/09getMoney/03bankCard/01addBankCard/addBankCard' + urlParam,
         path: '/01login/regUser/userReg' + urlParam,
         success: function(res) {
            console.log("【分享成功res】===", res)
            var pages = getCurrentPages() //获取加载的页面
            var currentPage = pages[pages.length - 1] //获取当前页面的对象
            app.getShareInfo(res, '邀请法人认证', currentPage.route)
         }
      }
   },

   //本人是法人(跳转到用户注册页面)
   gotoRegUser: function(e) {
      wx.navigateTo({
         //url: '/03admin/09getMoney/03bankCard/01addBankCard/addBankCard?scene=Biz_ID.' + app.Data.shopInfo.Biz_ID + '.User_ID.' + app.Data.userInfo.User_ID
         url: '/02login/02regUser/regUser?scene=BizID.' + _opt.Biz_ID + '.User_ID.' + app.Data.userInfo.User_ID
      }) 
   },
})